package com.yax.mickey.controller;

import com.yax.mickey.common.result.Result;
import com.yax.mickey.entity.Product;
import com.yax.mickey.service.ProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@ResponseBody
@RestController
@RequestMapping("/product")
@Api(tags = "用户端商品相关接口")
@Slf4j
public class ProductController {
    @Autowired
    private ProductService productService;

    @GetMapping("/getAllProducts")
    @ApiOperation("获取所有商品信息")
    public Result<List<Product>> getAllProducts() {
        List<Product> productList = productService.getAllProducts();
        return Result.success(productList);
    }

    @GetMapping("/getProductById/{productId}")
    @ApiOperation("根据商品ID查询商品")
    public Result<Product> getProductById(@PathVariable Integer productId) {
//        log.info("查询"+productId);
        Product product = productService.getProductById(productId);
        return Result.success(product);
    }

    @GetMapping("/getProductByCategoryId/{categoryId}")
    @ApiOperation("根据分类ID查询商品")
    public Result<List<Product>> getProductByCategoryId(@PathVariable  Integer categoryId) {
        List<Product> product = productService.getProductByCategoryId(categoryId);
        return Result.success(product);
    }

    @GetMapping("/getProductBySearch")
    @ApiOperation("搜索关键字模糊查询商品")
    public Result<List<Product>> getProductBySearch(@RequestParam String productName) {
        List<Product> productList = productService.getProductBySearch(productName);
        return Result.success(productList);
    }
}
